<template>
  <div>
    <h1>获取学校名称：{{ schoolName }}</h1>
    <h1>获取学生名称：{{ studentName }}</h1>
    <School @getSchoolName="getSchoolName" />
    <Student ref="stu" />
  </div>
</template>

<script>
import School from './components/School.vue'
import Student from './components/Student.vue'
export default {
  data() {
    return {
      schoolName: '',
      studentName: ''
    }
  },
  components: {
    School,
    Student
  },
  methods: {
    getSchoolName(val) {
      this.schoolName = val
    },
    getStudentName(val) {
      this.studentName = val
    }
  },
  mounted() {
    setTimeout(() => {
      this.$refs.stu.$on('getStudentName', this.getStudentName)
    }, 3000);
  }
}
</script>